import { HandleStatus } from '../../../../libs/db/src/entity/enum/handle-status.enum';
import { Injectable, Logger as _Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TypeOrmCrudService } from '@nestjsx/crud-typeorm';
import { Area } from 'libs/db/entity/area.entity';
import softDelete from '../_decorator/soft-delete.decorator';
import { Logger } from 'libs/db/entity/logger.entity';
import { LoggerService as NestLoggerService } from '@nestjs/common';
import { CrudRequest, Override } from '@nestjsx/crud';
import { Repository } from 'typeorm';

@Injectable()
export class LoggerService extends TypeOrmCrudService<Logger> implements NestLoggerService  {
  constructor(@InjectRepository(Logger) repo, private readonly _logger: _Logger) {
    super(repo);
  }
  
  //打印
  log(message: any, context?: string) {
    this._logger.log(message, context)
  }
  //打印 和 持久化
  _log(message: any, context: string, Logger: Logger) {
    this.log(message, context)
    this.createOneLogger(Logger)
  }
  error(message: any, trace?: string, context?: string) {
    this._logger.error(message, trace, context)
  }
  _error(message: any, trace: string, context: string, Logger: Logger) {
    this._logger.error(message, trace, context)
    this.createOneLogger(Logger)
  }
  warn(message: any, context?: string) {
    this._logger.warn(message, context)
  }
  _warn(message: any, context: string, Logger: Logger) {
    this._logger.warn(message, context)
    this.createOneLogger(Logger)
  }
  debug(message: any, context?: string) {
    this._logger.debug(message, context)
  }
  _debug(message: any, context: string, Logger: Logger) {
    this._logger.debug(message, context)
    this.createOneLogger(Logger)
  }
  verbose?(message: any, context?: string) {
    this._logger.verbose(message, context)
  }
  _verbose(message: any, context: string, Logger: Logger) {
    this._logger.verbose(message, context)
    this.createOneLogger(Logger)
  }

  async createOneLogger(logger :Logger) {
    await this.repo.insert(logger)
  }
}